#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <string.h>

using namespace std;

string head;
int cnt,total;
map<string,int>weight;
map<string,bool>visit;
map<string,vector<string> >adjlist;
map<string,int>res;

void DFS(string start)
{
    visit[start]=1;
    cnt++;
    total+=weight[start];
    if(weight[start]>weight[head]) head=start;

    for(auto it=adjlist[start].begin();it!=adjlist[start].end();it++)
    {
        if(visit[*it]==0)
        {
            DFS(*it);
        }
    }
}

int main()
{
    int N,K,T,i=0;
    cin>>N>>K;
    string member1,member2;
    while(i<N)
    {
        cin>>member1>>member2>>T;
        weight[member1]+=T;
        weight[member2]+=T;
        adjlist[member1].push_back(member2);
        adjlist[member2].push_back(member1);
        visit[member1]=0;
        visit[member2]=0;
        i++;
    }

    for(auto it=visit.begin();it!=visit.end();it++)
    {
        if(it->second==0)
        {
            total=0;
            cnt=0;
            head=it->first;
            DFS(it->first);
        }
        if(cnt>2&&total/2>K) res[head]=cnt;
    }

    cout<<res.size()<<endl;
    for(auto it=res.begin();it!=res.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    return 0;
}